<?php
namespace app\scodetrace\controller;
use \think\Request;

class Scode extends \app\common\controller\Common {
	protected $modelname='Scode';

	public function check() {
		$scodeModel=model($this->modelname);
		return json_pack($scodeModel::check($this->param('scode')));
	}

	public function getLog() {
		$scodeModel=model($this->modelname);
		$res=$scodeModel->getLog($this->param('token'),$this->param('page',1),$this->param('limit',10));
		if ($res) {
			return json_pack($res);
		} else {
			return json_pack($scodeModel->getError(),400);
		}
	}

  public function download() {
    $res_id=$this->param('res_id');
    $cache=cache('SCODE_GEN'.$res_id);
    if (!$cache) {
      return $this->error("你请求的资源不存在或暂未生成完毕，请稍后再试",null,404);
    }
    return download($cache['file'],'防伪码'.$res_id.'.txt');
  }
}

?>